package cn.thoughtworks.school.repositories;

import cn.thoughtworks.school.entities.Assignment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface AssignmentDiffRepository extends JpaRepository<Assignment, Long> {
    Assignment findFirst1ByAssignmentIdOrderByIdDesc(Long assignmentId);


    @Query(value = "select * from assignment where id in (\n" +
        "select max(id) from assignment t where\n" +
        "t.taskId in ?1 group by taskId,assignmentId order by assignmentId desc\n" +
        ") and operation != 2 ",nativeQuery = true)
    List<Assignment> findFirst1ByIdAndProgramIdInOrderByTasksIdDesc(List<Long> ids);

    List<Assignment> findByTaskIdOrderByIdDesc(Long taskId);
}
